import { Component, NgZone, OnInit, Inject } from '@angular/core';

// 服务
import { LoadingAnimateService } from './loading.service';

@Component({
    moduleId: module.id,
    selector: 'loading-animate',
    templateUrl: 'loading.component.html',
    styleUrls: ['loading.component.css']
})

export class LoadingComponent implements OnInit {
    isShow: number = 0;
    width: number;
    height: number;
    top: number;
    left: number;
    loadingState: string = 'inactive';

    ngOnInit(): void {
        //   console.log(`LoadingComponent init`);
        this.getPosition();
        this._loadingSvc.getValue().subscribe((status: boolean) => {
            //   console.log(`status+${status}`);
            this.loadingState = status ? 'active' : 'inactive';
        });
    }

    constructor(
        ngZone: NgZone,
        // @Inject('Window') window: Window,
        private _loadingSvc: LoadingAnimateService) {
        window.onresize = (e) => {
            ngZone.run(() => {
                this.getPosition();
            });
        };
    }
    getPosition(): void {
        this.width = window.innerWidth;
        this.height = window.innerHeight;
        this.left = this.width ? (this.width + 200) / 2 : 0;
        this.top = this.height ? this.height / 2 : 0;
    }
}